{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 作者：chenyujing（微信号:15280006510  QQ: 594462206）,欢迎交流\n",
    "################ \n",
    "##  使用者一定要准备的工作：\n",
    "##### 1.打开快手直播程序，最大化后，最小化在任务栏中，且放在任务栏中的第一个\n",
    "##### 2.打开OBS程序，最大化后，最小化在任务栏中，且放在任务栏中的第二个\n",
    "#       且确保：（1）处于“启动虚拟摄像机”模式；\n",
    "#               （2）视频选择好了；\n",
    "#               （3）是有显示“播放”“停止”按钮模式（方法是：在播放的视频处点击一下），\n",
    "#                    且处于“停止”状态（要点下停止按钮）\n",
    "##### 3. 配置每天开始直播与结束直播的时间及配置快手程序个数(见下面)\n",
    "##### 4. 配置完时间后，运行此脚本：Cell -> Run All \n",
    "#        运行后，把浏览器最小化就好（切记，不要关注这个浏览器页面”；\n",
    "#        也不要关闭“管理员：Anaconda Prompt”这个命令窗口）\n",
    "#     5. 注意：如果脚本一旦运行起来，想修改配置数据，需要先将程序停止，然后再启动脚本 \n",
    "#        停止脚本的方法：Kernel -> Restart"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "######## 配置每天开始直播的时间 #########################\n",
    "######## 注意： 配置数据时要人为保证（否则程序会出错）：\n",
    "########        1）开始直播后，至少要等5分钟后，才能停止直播\n",
    "#######         2）停止直播后，至少再等5分钟后，才能再是直播\n",
    "g_BEGIN_PLAY_TIME_LIST = [\"9:18\", \"10:25\"]\n",
    "\n",
    "######## 配置每天结束直播的时间 #########################\n",
    "g_STOP_PLAY_TIME_LIST = [\"10:18\", \"11:25\"]\n",
    "\n",
    "######## 配置当前运行的快手程序的个数 ###############################\n",
    "COUNT_OF_KUAI_SHOU = 4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'expires_in': 2592000, 'access_token': '24.2091e65656e515fda033f00cdfa9bf25.2592000.1672494276.282335-10955179', 'session_secret': 'be9c031dac48dec23532539f11ee96dc', 'session_key': '9mzdCSYL43E797/ZnzZbfMGx01TP4eFkkP1D/puohcKIo5HvijC7XccaX/NtMvt4TNdT64Yyfq4m5EwTwxejq1pj4ClpXQ==', 'refresh_token': '25.c0465224272a19aeeb0049d7e72cb6bf.315360000.1985262276.282335-10955179', 'scope': 'brain_ocr_meter brain_doc_analysis brain_ocr_webimage_loc vis-ocr_机动车购车发票识别 brain_ocr_vehicle_invoice brain_formula vis-ocr_行程单识别 brain_ocr_air_ticket brain_qrcode brain_ocr_business_card vis-ocr_保单识别 brain_ocr_insurance_doc vis-ocr_vis-classify_birth_certificate vis-ocr_台湾通行证 vis-ocr_港澳通行证 brain_ocr_birth_certificate brain_ocr_HK_Macau_pass brain_ocr_taiwan_pass brain_solution_iocr vis-ocr_household_register vis-ocr_机动车检验合格证识别 brain_ocr_household_register brain_ocr_vehicle_certificate brain_ocr_passport vis-ocr_定额发票识别 brain_ocr_quota_invoice vis-ocr_车辆vin码识别 brain_ocr_vin brain_ocr_train_ticket brain_ocr_taxi_receipt brain_numbers brain_ocr_vat_invoice brain_ocr_handwriting public vis-ocr_ocr brain_ocr_scope brain_ocr_general brain_ocr_general_basic brain_ocr_general_enhanced vis-ocr_business_license brain_ocr_webimage brain_all_scope brain_ocr_idcard brain_ocr_driving_license brain_ocr_vehicle_license vis-ocr_plate_number brain_solution brain_ocr_plate_number brain_ocr_accurate brain_ocr_accurate_basic brain_ocr_receipt brain_ocr_business_license wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online smartapp_gov_aladin_to_xcx'}\n",
      "16000\n",
      "屏幕的分辨率是1366*768\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'\\nKUAI_SHOU_1_ICON_X = LEI_DIAN_FW_LEFT + 465\\nKUAI_SHOU_1_ICON_Y =LEI_DIAN_FW_BOTTOM - 100\\nKUAI_SHOU_2_ICON_X = LEI_DIAN_FW_LEFT + 650\\nKUAI_SHOU_2_ICON_Y =LEI_DIAN_FW_BOTTOM - 100\\nKUAI_SHOU_3_ICON_X = LEI_DIAN_FW_LEFT + 650\\nKUAI_SHOU_3_ICON_Y =LEI_DIAN_FW_BOTTOM - 100\\nKUAI_SHOU_ICON_LIST[0][\"icon_pos\"] = (KUAI_SHOU_1_ICON_X, KUAI_SHOU_1_ICON_Y)\\nKUAI_SHOU_ICON_LIST[1][\"icon_pos\"] = (KUAI_SHOU_2_ICON_X, KUAI_SHOU_2_ICON_Y)\\nKUAI_SHOU_ICON_LIST[2][\"icon_pos\"] = (KUAI_SHOU_3_ICON_X, KUAI_SHOU_3_ICON_Y)\\n'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pyautogui\n",
    "import time \n",
    "import shutil \n",
    "import os\n",
    "import pyperclip\n",
    "import win32gui\n",
    "import stat\n",
    "from PIL import Image\n",
    "import time\n",
    "from random import sample\n",
    "import test_baidu_ocr  \n",
    "import random\n",
    "import win32clipboard as w\n",
    "import win32con\n",
    "from win32 import win32api, win32gui, win32print\n",
    "from win32.lib import win32con\n",
    "from enum import Enum\n",
    "#from pymouse import PyMouse\n",
    "import win32api\n",
    "import win32gui\n",
    "import win32con\n",
    "import datetime\n",
    "import schedule\n",
    " \n",
    "\n",
    "# 应用程序的标题\n",
    "KUI_SHOU_TITLE_BEGIN = \"快手直播伴侣\"\n",
    "OBS_TITLE_BEGIN = \"OBS\"\n",
    "# 临时图片保存的路径 \n",
    "SCREENSHOT_SAVE_DIR = \"./screenshot_img\"\n",
    "if False == os.path.exists(SCREENSHOT_SAVE_DIR):\n",
    "    os.mkdir(SCREENSHOT_SAVE_DIR)\n",
    "\n",
    "\n",
    "g_img_count = 0\n",
    "\n",
    "if True == os.path.exists(SCREENSHOT_SAVE_DIR):\n",
    "    # chenyj test\n",
    "    os.chmod(SCREENSHOT_SAVE_DIR, stat.S_IWUSR)\n",
    "    # chenyj test\n",
    "    #shutil.rmtree(SCREENSHOT_SAVE_DIR)\n",
    "    pass\n",
    "# chenyj test\n",
    "#os.mkdir(SCREENSHOT_SAVE_DIR)\n",
    "\n",
    "\n",
    "\n",
    "\"\"\"获取缩放后的分辨率\"\"\"\n",
    "g_sX = win32api.GetSystemMetrics(0)   #获得屏幕分辨率X轴\n",
    "g_sY = win32api.GetSystemMetrics(1)   #获得屏幕分辨率Y轴\n",
    "print(\"屏幕的分辨率是{}*{}\".format(g_sX, g_sY))\n",
    "\n",
    "# 配置以下数据时的分辨率\n",
    "g_sX_now = 1920\n",
    "g_sY_now = 1080\n",
    "# 快手第一个缩略图的位置  \n",
    "KUAI_FIRST_SUO_LUE_X = int(0/g_sX_now*g_sX)\n",
    "KUAI_FIRST_SUO_LUE_Y = int(890/g_sY_now*g_sY)\n",
    "KUAI_FIRST_SUO_LUE_R = int(214/g_sX_now*g_sX)\n",
    "KUAI_FIRST_SUO_LUE_B = int(1030/g_sY_now*g_sY)\n",
    "\n",
    "# 全屏应用程序左上角的Title的坐标\n",
    "TITLE_X_OF_SCREEN = 0\n",
    "TITLE_Y_OF_SCREEN = 0\n",
    "TITLE_R_OF_SCREEN = int(376/g_sX_now*g_sX)\n",
    "TITLE_B_OF_SCREEN = int(46/g_sY_now*g_sY)\n",
    "\n",
    "# OBS停止按钮 \n",
    "OBS_STOP_X = int(506/g_sX_now*g_sX)\n",
    "OBS_STOP_Y = int(732/g_sY_now*g_sY)\n",
    "# OBS开始/暂停按钮\n",
    "OBS_START_X = int(398/g_sX_now*g_sX)\n",
    "OBS_START_Y = int(732/g_sY_now*g_sY)\n",
    "# OBS播放时间 \n",
    "OBS_TIME_X = int(1790/g_sX_now*g_sX)\n",
    "OBS_TIME_Y = int(718/g_sY_now*g_sY)\n",
    "OBS_TIME_R = int(1914/g_sX_now*g_sX)\n",
    "OBS_TIME_B = int(752/g_sY_now*g_sY)\n",
    "# OBS最小化按钮\n",
    "OBS_SMALL_X = int(1788/g_sX_now*g_sX)\n",
    "OBS_SMALL_Y = int(2/g_sY_now*g_sY)\n",
    "OBS_SMALL_R = int(1820/g_sX_now*g_sX)\n",
    "OBS_SMALL_B = int(24/g_sY_now*g_sY)\n",
    "\n",
    "# 快手状态按钮\n",
    "#KUAI_SHOU_STATUS_X = int(890/g_sX_now*g_sX)\n",
    "#KUAI_SHOU_STATUS_Y = int(630/g_sY_now*g_sY)\n",
    "#KUAI_SHOU_STATUS_R = int(994/g_sX_now*g_sX)\n",
    "#KUAI_SHOU_STATUS_B = int(670/g_sY_now*g_sY)\n",
    "KUAI_SHOU_STATUS_X = int(1444/g_sX_now*g_sX)\n",
    "KUAI_SHOU_STATUS_Y = int(942/g_sY_now*g_sY)\n",
    "KUAI_SHOU_STATUS_R = int(1544/g_sX_now*g_sX)\n",
    "KUAI_SHOU_STATUS_B = int(982/g_sY_now*g_sY)\n",
    "# 快手开播放确定按钮\n",
    "KUAI_SHOU_PLAY_CONFIRM_X = int(880/g_sX_now*g_sX)\n",
    "KUAI_SHOU_PLAY_CONFIRM_Y = int(726/g_sY_now*g_sY)\n",
    "KUAI_SHOU_PLAY_CONFIRM_R = int(1020/g_sX_now*g_sX)\n",
    "KUAI_SHOU_PLAY_CONFIRM_B = int(762/g_sY_now*g_sY)\n",
    "# 快手直播关闭确定按钮\n",
    "KUAI_SHOU_STOP_CONFIRM_X = int(986/g_sX_now*g_sX)\n",
    "KUAI_SHOU_STOP_CONFIRM_Y = int(518/g_sY_now*g_sY)\n",
    "KUAI_SHOU_STOP_CONFIRM_R = int(1088/g_sX_now*g_sX)\n",
    "KUAI_SHOU_STOP_CONFIRM_B = int(554/g_sY_now*g_sY)\n",
    "# 快手直播停止结束后我知道子按钮\n",
    "#KUAI_SHOU_KNOW_X = int(664/g_sX_now*g_sX)\n",
    "#KUAI_SHOU_KNOW_Y = int(528/g_sY_now*g_sY)\n",
    "#KUAI_SHOU_KNOW_R = int(780/g_sX_now*g_sX)\n",
    "#KUAI_SHOU_KNOW_B = int(558/g_sY_now*g_sY)\n",
    "KUAI_SHOU_KNOW_X = int(1204/g_sX_now*g_sX)\n",
    "KUAI_SHOU_KNOW_Y = int(654/g_sY_now*g_sY)\n",
    "KUAI_SHOU_KNOW_R = int(1320/g_sX_now*g_sX)\n",
    "KUAI_SHOU_KNOW_B = int(686/g_sY_now*g_sY)\n",
    "# 快手最小化按钮\n",
    "KUAI_SHOU_SMALL_X = int(1812/g_sX_now*g_sX)\n",
    "KUAI_SHOU_SMALL_Y = int(24/g_sY_now*g_sY)\n",
    "KUAI_SHOU_SMALL_R = int(1838/g_sX_now*g_sX)\n",
    "KUAI_SHOU_SMALL_B = int(44/g_sY_now*g_sY)\n",
    "\n",
    "# 任务栏的高\n",
    "TASK_BANNER_HEITH = 40\n",
    "# 任务栏中的快手图标\n",
    "#   要求打开“快手直播助手伴侣”，且放在任务栏图标从左往右的第一个\n",
    "KUAI_SHOU_ICON_X = 76\n",
    "KUAI_SHOU_ICON_Y = g_sY - TASK_BANNER_HEITH + int(TASK_BANNER_HEITH/2)\n",
    "# 任务栏中的OBS图标\n",
    "#   要求打开“OBS”，且放在任务栏图标从左往右的第二个\n",
    "OBS_ICON_X = 124\n",
    "OBS_ICON_Y = g_sY - TASK_BANNER_HEITH + int(TASK_BANNER_HEITH/2)\n",
    "# 任务栏中的微信聊天图标\n",
    "#   要求打开“文件传输助手”，且放在任务栏图标从左往右的第三个\n",
    "WEI_XIN_ICON_X = 172\n",
    "WEI_XIN_ICON_Y = g_sY - TASK_BANNER_HEITH + int(TASK_BANNER_HEITH/2)\n",
    "\n",
    "# 任务栏上方的快手的应用程序图标列表\n",
    "\"\"\"\n",
    "KUAI_SHOU_1_ICON_X = LEI_DIAN_FW_LEFT + 465\n",
    "KUAI_SHOU_1_ICON_Y =LEI_DIAN_FW_BOTTOM - 100\n",
    "KUAI_SHOU_2_ICON_X = LEI_DIAN_FW_LEFT + 650\n",
    "KUAI_SHOU_2_ICON_Y =LEI_DIAN_FW_BOTTOM - 100\n",
    "KUAI_SHOU_3_ICON_X = LEI_DIAN_FW_LEFT + 650\n",
    "KUAI_SHOU_3_ICON_Y =LEI_DIAN_FW_BOTTOM - 100\n",
    "KUAI_SHOU_ICON_LIST[0][\"icon_pos\"] = (KUAI_SHOU_1_ICON_X, KUAI_SHOU_1_ICON_Y)\n",
    "KUAI_SHOU_ICON_LIST[1][\"icon_pos\"] = (KUAI_SHOU_2_ICON_X, KUAI_SHOU_2_ICON_Y)\n",
    "KUAI_SHOU_ICON_LIST[2][\"icon_pos\"] = (KUAI_SHOU_3_ICON_X, KUAI_SHOU_3_ICON_Y)\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 获取屏幕左上角的Title的名称\n",
    "def get_tilte_of_full_screen():\n",
    "    title_return = \"\"\n",
    "    \n",
    "    img_after_cut_path = SCREENSHOT_SAVE_DIR + \"/\" + \"top_banner\" + \".png\"\n",
    "    pyautogui.screenshot(img_after_cut_path, region=(TITLE_X_OF_SCREEN, TITLE_Y_OF_SCREEN, TITLE_R_OF_SCREEN, TITLE_B_OF_SCREEN))\n",
    "    print('Top banner保存到:{}'.format(img_after_cut_path))\n",
    "    ocr_result = test_baidu_ocr.get_ocr_result(img_after_cut_path)\n",
    "    print(\"OCR的结果：\", ocr_result)\n",
    "    for word_result in ocr_result[\"words_result\"]:\n",
    "        words = word_result[\"words\"]\n",
    "        location = word_result[\"location\"]\n",
    "        title_return += words\n",
    "    return title_return\n",
    "\n",
    "# 让当前全屏的应用程序在最顶部\n",
    "def set_app_forward():\n",
    "    pyautogui.moveTo(TITLE_R_OF_SCREEN/3, TITLE_B_OF_SCREEN/3,duration=0.5)\n",
    "    pyautogui.click()\n",
    "     \n",
    "    #m = PyMouse()\n",
    "    #m.click(int(TITLE_R_OF_SCREEN/3), int(TITLE_B_OF_SCREEN/3))  \n",
    "    \n",
    "    \"\"\"\n",
    "    mainHnd = win32gui.FindWindow(None,\"快手直播伴侣\")\n",
    "    print(mainHnd)\n",
    "    #模拟鼠标指针， 传送到指定坐标\n",
    "    long_position = win32api.MAKELONG(int(TITLE_R_OF_SCREEN/3), int(TITLE_B_OF_SCREEN/3))\n",
    "    # 模拟鼠标按下\n",
    "    win32api.SendMessage(mainHnd, win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON, long_position)\n",
    "    # 模拟鼠标弹起\n",
    "    win32api.SendMessage(mainHnd, win32con.WM_LBUTTONUP, win32con.MK_LBUTTON, long_position)\n",
    "    \"\"\"\n",
    "    time.sleep(0.5)\n",
    "    return\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "\n",
    "#set_app_forward()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "\n",
    "# 判断当前是不是OBS全屏\n",
    "def is_obs_full_scree():\n",
    "    fw_all = pyautogui.getAllWindows() # 返回屏幕上每个可见窗口的窗口对象列表。\n",
    "    b_found = False\n",
    "    for fw in fw_all:\n",
    "        if OBS_TITLE_BEGIN in fw.title:\n",
    "            #print(fw)\n",
    "            print(\"OBS窗口【{}】的坐标是:({}, {}, {}, {})\".format(fw.title, fw.left, fw.top, fw.right, fw.bottom))\n",
    "            if fw.left <= 0 and fw.top <= 0 and fw.right >= g_sX and fw.bottom >= (g_sY - TASK_BANNER_HEITH):\n",
    "                title_return = get_tilte_of_full_screen()\n",
    "                if OBS_TITLE_BEGIN not in title_return:\n",
    "                    continue\n",
    "                return True\n",
    "    return False\n",
    "\n",
    "# OBS界面点击停止按钮\n",
    "def obs_stop():\n",
    "    print(\"点击【OBS界面点击停止】按钮\")\n",
    "    pyautogui.moveTo(OBS_STOP_X, OBS_STOP_Y,duration=0.5)\n",
    "    pyautogui.click()\n",
    "    \n",
    "# OBS界面点击开始或暂停按钮\n",
    "def obs_start_or_pause():\n",
    "    print(\"点击【OBS界面点击开始或暂停】按钮\")\n",
    "    pyautogui.moveTo(OBS_START_X, OBS_START_Y,duration=0.5)\n",
    "    pyautogui.click()\n",
    "\n",
    "# 判断OBS当前是不是在播放\n",
    "def is_obs_playing():\n",
    "    title_return = \"\"\n",
    "    \n",
    "    img_after_cut_path = SCREENSHOT_SAVE_DIR + \"/\" + \"time_of_obs\" + \".png\"\n",
    "    pyautogui.screenshot(img_after_cut_path, region=(OBS_TIME_X, OBS_TIME_Y, OBS_TIME_R - OBS_TIME_X, OBS_TIME_B - OBS_TIME_Y))\n",
    "    print('time_of_obs保存到:{}'.format(img_after_cut_path))\n",
    "    ocr_result = test_baidu_ocr.get_ocr_result(img_after_cut_path)\n",
    "    print(\"OCR的结果：\", ocr_result)\n",
    "    for word_result in ocr_result[\"words_result\"]:\n",
    "        words = word_result[\"words\"]\n",
    "        location = word_result[\"location\"]\n",
    "        title_return += words\n",
    "    if \"0\" in title_return:\n",
    "        return True\n",
    "    return False\n",
    "\n",
    "\n",
    "# OBS界面最小化按钮\n",
    "def obs_smallest():\n",
    "    print(\"点击【OBS界面最小化】按钮\")\n",
    "    pyautogui.moveTo(OBS_SMALL_X + int((OBS_SMALL_R - OBS_SMALL_X)/2), OBS_SMALL_Y + int((OBS_SMALL_B - OBS_SMALL_Y)/2),duration=0.5)\n",
    "    pyautogui.click()\n",
    "    time.sleep(0.5)\n",
    "    return\n",
    "\n",
    "# OBS界面还原按钮 \n",
    "def obs_restore():\n",
    "    print(\"点击【OBS界面还原】按钮\")\n",
    "    pyautogui.moveTo(OBS_ICON_X, OBS_ICON_Y,duration=0.5)\n",
    "    pyautogui.click()\n",
    "    time.sleep(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#<Win32Window left=\"0\", top=\"0\", width=\"1418\", height=\"813\", title=\"快手直播伴侣\">\n",
    "#屏幕的分辨率是1366*768\n",
    "# 判断当前是不是快手直播伴侣全屏\n",
    "def is_kuai_shou_full_scree():\n",
    "    fw_all = pyautogui.getAllWindows() # 返回屏幕上每个可见窗口的窗口对象列表。\n",
    "    b_found = False\n",
    "    for fw in fw_all:\n",
    "        if KUI_SHOU_TITLE_BEGIN in fw.title:\n",
    "            #print(fw)\n",
    "            print(\"快手直播伴侣窗口【{}】的坐标是:({}, {}, {}, {})\".format(fw.title, fw.left, fw.top, fw.right, fw.bottom)) \n",
    "            if fw.left <= 0 and fw.top <= 0 and fw.right >= g_sX and fw.bottom >= (g_sY - TASK_BANNER_HEITH):\n",
    "                title_return = get_tilte_of_full_screen()\n",
    "                print(title_return)\n",
    "                if KUI_SHOU_TITLE_BEGIN not in title_return:\n",
    "                    continue\n",
    "                return True\n",
    "    return False\n",
    "\n",
    "# 判断快手当前是不是在播放\n",
    "class KUAI_SHOUO_STUTUS(Enum):\n",
    "    STOPPED = 1\n",
    "    PLAYING = 2\n",
    "    CONNECTING = 3\n",
    "    OTHER = 4\n",
    "def get_kuai_shou_status():\n",
    "    title_return = \"\"\n",
    "    \n",
    "    img_after_cut_path = SCREENSHOT_SAVE_DIR + \"/\" + \"status_of_kuai_shou\" + \".png\"\n",
    "    pyautogui.screenshot(img_after_cut_path, region=(KUAI_SHOU_STATUS_X, KUAI_SHOU_STATUS_Y, KUAI_SHOU_STATUS_R - KUAI_SHOU_STATUS_X, KUAI_SHOU_STATUS_B - KUAI_SHOU_STATUS_Y))\n",
    "    print('status_of_kuai_shou保存到:{}'.format(img_after_cut_path))\n",
    "    ocr_result = test_baidu_ocr.get_ocr_result(img_after_cut_path)\n",
    "    print(\"OCR的结果：\", ocr_result)\n",
    "    for word_result in ocr_result[\"words_result\"]:\n",
    "        words = word_result[\"words\"]\n",
    "        location = word_result[\"location\"]\n",
    "        title_return += words\n",
    "    if \"开始直播\" in title_return:\n",
    "        return KUAI_SHOUO_STUTUS.STOPPED\n",
    "    if \"关闭直播\" in title_return:\n",
    "        return KUAI_SHOUO_STUTUS.PLAYING\n",
    "    if \"连接中\" in title_return:\n",
    "        return KUAI_SHOUO_STUTUS.CONNECTING\n",
    "    return KUAI_SHOUO_STUTUS.OTHER\n",
    "\n",
    "# 快手界面点击开始或暂停按钮\n",
    "def kuai_shou_start_or_stop():\n",
    "    print(\"点击【快手界面点击开始或暂停】按钮\")\n",
    "    pyautogui.moveTo(KUAI_SHOU_STATUS_X + (KUAI_SHOU_STATUS_R - KUAI_SHOU_STATUS_X)/2, KUAI_SHOU_STATUS_Y + (KUAI_SHOU_STATUS_B - KUAI_SHOU_STATUS_Y)/2 ,duration=0.5)\n",
    "    pyautogui.click()\n",
    "    return\n",
    "\n",
    "\n",
    "# 快手界面点击开播确定按钮\n",
    "def kuai_confirm_of_play():\n",
    "    print(\"点击【快手界面点击开播确定】按钮\")\n",
    "    pyautogui.moveTo(KUAI_SHOU_PLAY_CONFIRM_X + (KUAI_SHOU_PLAY_CONFIRM_R - KUAI_SHOU_PLAY_CONFIRM_X)/2, KUAI_SHOU_PLAY_CONFIRM_Y + (KUAI_SHOU_PLAY_CONFIRM_B - KUAI_SHOU_PLAY_CONFIRM_Y)/2 ,duration=0.5)\n",
    "    pyautogui.click()\n",
    "    return\n",
    "\n",
    "# 快手界面点击关闭直播确定按钮\n",
    "def kuai_confirm_of_stop():\n",
    "    print(\"点击【快手界面点击关闭直播确定】按钮\")\n",
    "    pyautogui.moveTo(KUAI_SHOU_STOP_CONFIRM_X + int((KUAI_SHOU_STOP_CONFIRM_R - KUAI_SHOU_STOP_CONFIRM_X)/2), KUAI_SHOU_STOP_CONFIRM_Y + int((KUAI_SHOU_STOP_CONFIRM_B - KUAI_SHOU_STOP_CONFIRM_Y)/2),duration=0.5)\n",
    "    pyautogui.click()\n",
    "    return\n",
    "\n",
    "# 快手界面停止我知道了按钮\n",
    "\"\"\"\n",
    "def kuai_know_of_stop():\n",
    "    print(\"点击【快手界面我知道了】按钮\")\n",
    "    pyautogui.moveTo(KUAI_SHOU_KNOW_X + int((KUAI_SHOU_KNOW_R - KUAI_SHOU_KNOW_X)/2), KUAI_SHOU_KNOW_Y + int((KUAI_SHOU_KNOW_B - KUAI_SHOU_KNOW_Y)/2),duration=0.5)\n",
    "    pyautogui.click()\n",
    "    return\n",
    "\"\"\"\n",
    "def kuai_know_of_stop():\n",
    "    b_found_know = False\n",
    "    # 找“我知道了按钮”\n",
    "    img_after_cut_path = SCREENSHOT_SAVE_DIR + \"/\" + \"full_screen_for_know\" + \".png\"\n",
    "    pyautogui.screenshot(img_after_cut_path, region=(0, 0, g_sX, g_sY))\n",
    "    print('full_screen_for_know保存到:{}'.format(img_after_cut_path))\n",
    "    ocr_result = test_baidu_ocr.get_ocr_result(img_after_cut_path)\n",
    "    print(\"OCR的结果：\", ocr_result)\n",
    "    for word_result in ocr_result[\"words_result\"]:\n",
    "        words = word_result[\"words\"]\n",
    "        location = word_result[\"location\"]\n",
    "        if \"知道\" in words:\n",
    "            b_found_know = True\n",
    "            #{'location': {'height': 12, 'top': 4, 'width': 348, 'left': 23}\n",
    "            KUAI_SHOU_KNOW_X = location[\"left\"]\n",
    "            KUAI_SHOU_KNOW_Y = location[\"top\"]\n",
    "            KUAI_SHOU_KNOW_R = KUAI_SHOU_KNOW_X + location[\"width\"]\n",
    "            KUAI_SHOU_KNOW_B = KUAI_SHOU_KNOW_Y + location[\"height\"]\n",
    "            break\n",
    "            \n",
    "    if b_found_know == False:\n",
    "        print(\"!!!!!!没找到“我知道了”按钮\")\n",
    "        return False\n",
    "    \n",
    "    print(\"点击【快手界面我知道了】按钮\")\n",
    "    pyautogui.moveTo(KUAI_SHOU_KNOW_X + int((KUAI_SHOU_KNOW_R - KUAI_SHOU_KNOW_X)/2), KUAI_SHOU_KNOW_Y + int((KUAI_SHOU_KNOW_B - KUAI_SHOU_KNOW_Y)/2),duration=0.5)\n",
    "    pyautogui.click()\n",
    "    return\n",
    "    \n",
    "# 快手界面最小化按钮\n",
    "def kuai_smallest():\n",
    "    print(\"点击【快手界面最小化】按钮\")\n",
    "    pyautogui.moveTo(KUAI_SHOU_SMALL_X + int((KUAI_SHOU_SMALL_R - KUAI_SHOU_SMALL_X)/2), KUAI_SHOU_SMALL_Y + int((KUAI_SHOU_SMALL_B - KUAI_SHOU_SMALL_Y)/2),duration=0.5)\n",
    "    pyautogui.click()\n",
    "    time.sleep(0.5)\n",
    "    return\n",
    "\n",
    "# 快手界面还原按钮 \n",
    "def kuai_restore():\n",
    "    print(\"点击【快手界面还原】按钮\")\n",
    "    pyautogui.moveTo(KUAI_SHOU_ICON_X, KUAI_SHOU_ICON_Y,duration=0.5)\n",
    "    pyautogui.click()\n",
    "    time.sleep(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'\\nb_full_screen = is_obs_full_scree()\\nif b_full_screen == True:\\n    print(\"OBS应用程序全屏显示\")\\n    # 让应用程序置顶\\n    set_app_forward()\\n    if True == is_obs_playing():\\n        print(\"当前正在播放\")\\n    else:\\n        print(\"当前没在播放\")\\n    obs_start_or_pause()\\n    time.sleep(1)\\n    obs_stop()\\n    time.sleep(1)\\nelse:\\n    print(\"OBS应用程序没有全屏显示\")\\n\\n\\n# 测试快手直播伴侣\\nb_full_screen = is_kuai_shou_full_scree()\\nif b_full_screen == True:\\n    print(\"快手直播伴侣应用程序全屏显示\")\\n    # 让应用程序置顶\\n    set_app_forward()\\n    time.sleep(0.5)\\n    status = get_kuai_shou_status()\\n    if KUAI_SHOUO_STUTUS.PLAYING == status:\\n        print(\"当前正在直播\")\\n        kuai_shou_start_or_stop()\\n        time.sleep(1)\\n        kuai_confirm_of_stop()\\n        time.sleep(1)\\n        kuai_know_of_stop()\\n    elif KUAI_SHOUO_STUTUS.STOPPED == status:\\n        print(\"当前没在直播\")\\n        kuai_shou_start_or_stop()\\n        time.sleep(1)\\n        kuai_confirm_of_play()\\n    elif KUAI_SHOUO_STUTUS.OTHER == status:\\n        print(\"当前快手应用程序被挡住\")\\nelse:\\n    print(\"快手直播伴侣应用程序没有全屏显示\")\\n'"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 测试OBS \n",
    "\"\"\"\n",
    "b_full_screen = is_obs_full_scree()\n",
    "if b_full_screen == True:\n",
    "    print(\"OBS应用程序全屏显示\")\n",
    "    # 让应用程序置顶\n",
    "    set_app_forward()\n",
    "    if True == is_obs_playing():\n",
    "        print(\"当前正在播放\")\n",
    "    else:\n",
    "        print(\"当前没在播放\")\n",
    "    obs_start_or_pause()\n",
    "    time.sleep(1)\n",
    "    obs_stop()\n",
    "    time.sleep(1)\n",
    "else:\n",
    "    print(\"OBS应用程序没有全屏显示\")\n",
    "\n",
    "\n",
    "# 测试快手直播伴侣\n",
    "b_full_screen = is_kuai_shou_full_scree()\n",
    "if b_full_screen == True:\n",
    "    print(\"快手直播伴侣应用程序全屏显示\")\n",
    "    # 让应用程序置顶\n",
    "    set_app_forward()\n",
    "    time.sleep(0.5)\n",
    "    status = get_kuai_shou_status()\n",
    "    if KUAI_SHOUO_STUTUS.PLAYING == status:\n",
    "        print(\"当前正在直播\")\n",
    "        kuai_shou_start_or_stop()\n",
    "        time.sleep(1)\n",
    "        kuai_confirm_of_stop()\n",
    "        time.sleep(1)\n",
    "        kuai_know_of_stop()\n",
    "    elif KUAI_SHOUO_STUTUS.STOPPED == status:\n",
    "        print(\"当前没在直播\")\n",
    "        kuai_shou_start_or_stop()\n",
    "        time.sleep(1)\n",
    "        kuai_confirm_of_play()\n",
    "    elif KUAI_SHOUO_STUTUS.OTHER == status:\n",
    "        print(\"当前快手应用程序被挡住\")\n",
    "else:\n",
    "    print(\"快手直播伴侣应用程序没有全屏显示\")\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "########## GUI 控制功能\n",
    "# 控制鼠标键盘使用的模块为：pyautogui，这个模块操作起鼠标键盘的时候，非常的迅速，\n",
    "# 而且如果该模块控制了鼠标后，程序比较难关闭，这时我们有两个方法专门针对以上的情况\n",
    "# 自动 防故障功能\n",
    "#      默认这项功能为True, 这项功能意味着：当鼠标的指针在屏幕的最坐上方，程序会报错；目的是为了防止程序无法停止；\n",
    "pyautogui.FAILSAFE = True  \n",
    "\n",
    "# 停顿功能\n",
    "#     意味着所有pyautogui的指令都要暂停一秒；其他指令不会停顿；这样做，可以防止键盘鼠标操作太快；\n",
    "pyautogui.PAUSE = 0.2\n",
    "# 调用每个PyAutoGUI函数后，会有十分之一秒的延迟，使用户有时间将鼠标猛撞到角落以触发故障保险。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 微信通知 \n",
    "def wei_xin_notify(str_in):\n",
    "    str_in = \"【jupyter自动化】\" + str_in\n",
    "    print(str_in)\n",
    "    pyautogui.moveTo(WEI_XIN_ICON_X, WEI_XIN_ICON_Y,duration=0.5)\n",
    "    pyautogui.click()\n",
    "    time.sleep(1)\n",
    "    pyperclip.copy(str_in)\n",
    "    time.sleep(1)\n",
    "    pyautogui.hotkey('Ctrl', 'v')\n",
    "    time.sleep(0.5)\n",
    "    pyautogui.press('enter') \n",
    "    time.sleep(6)\n",
    "    pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#str_in = \"主人，【 】主页发现了新作品\"\n",
    "#wei_xin_notify(str_in)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 获取剪切板内容 \n",
    "import win32clipboard as w\n",
    "import win32con\n",
    "def get_text():\n",
    "    w.OpenClipboard()\n",
    "    d = w.GetClipboardData(win32con.CF_TEXT)\n",
    "    w.CloseClipboard()\n",
    "    return d.decode('GBK')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 还原指定序号的快手程序\n",
    "def restore_selected_kuai_shou_app(index):\n",
    "    KUAI_FIRST_SUO_LUE_X\n",
    "    print(\"点击【第{}个快手程序的缩略图】按钮\".format(index))\n",
    "    x = KUAI_FIRST_SUO_LUE_X + index * (KUAI_FIRST_SUO_LUE_R - KUAI_FIRST_SUO_LUE_X)\n",
    "    pyautogui.moveTo(x  + int((KUAI_FIRST_SUO_LUE_R - KUAI_FIRST_SUO_LUE_X)/2), KUAI_FIRST_SUO_LUE_Y + int((KUAI_FIRST_SUO_LUE_B - KUAI_FIRST_SUO_LUE_Y)/2),duration=0.5)\n",
    "    pyautogui.click()\n",
    "    time.sleep(1)\n",
    "    return"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 开始快手直播(仅操作这一部分)\n",
    "def begin_kuai_shou_play__():\n",
    "    bResult = False\n",
    "    \n",
    "    b_full_screen = is_kuai_shou_full_scree()\n",
    "    if b_full_screen == True:\n",
    "        print(\"快手直播应用程序全屏显示\")\n",
    "        # 让应用程序置顶\n",
    "        set_app_forward()\n",
    "        time.sleep(0.5)\n",
    "        status = get_kuai_shou_status()\n",
    "        if KUAI_SHOUO_STUTUS.PLAYING == status:\n",
    "            print(\"当前正在直播\")\n",
    "            bResult = True\n",
    "        elif KUAI_SHOUO_STUTUS.STOPPED == status:\n",
    "            print(\"当前没在直播\")\n",
    "            kuai_shou_start_or_stop()\n",
    "            time.sleep(2)\n",
    "            kuai_confirm_of_play()\n",
    "            time.sleep(2)\n",
    "            status_now = get_kuai_shou_status()\n",
    "            if KUAI_SHOUO_STUTUS.PLAYING == status_now:\n",
    "                bResult = True\n",
    "            else:\n",
    "                bResult = False\n",
    "        elif KUAI_SHOUO_STUTUS.CONNECTING == status:\n",
    "            print(\"当前快手正在连接中\")\n",
    "            bResult = False\n",
    "        elif KUAI_SHOUO_STUTUS.OTHER == status:\n",
    "            print(\"当前快手应用程序被挡住\")\n",
    "            bResult = False\n",
    "    else:\n",
    "        print(\"!!!!!快手直播应用程序没有全屏显示\")\n",
    "        return False\n",
    "    kuai_smallest()\n",
    "    return bResult\n",
    "\n",
    "\n",
    "\n",
    "# 开始快手直播\n",
    "def begin_kuai_shou_play():\n",
    "    if 1 == COUNT_OF_KUAI_SHOU:\n",
    "        kuai_restore()\n",
    "        return begin_kuai_shou_play__()\n",
    "    else:\n",
    "        for i in range(COUNT_OF_KUAI_SHOU):\n",
    "            kuai_restore()\n",
    "            restore_selected_kuai_shou_app(i)\n",
    "            bResult = begin_kuai_shou_play__()\n",
    "            if bResult == False:\n",
    "                print(\"!!!!!第【{}】个快手程序的开始播放失败了\".format(i))\n",
    "                return False\n",
    "            else:\n",
    "                print(\"!!!!!第【{}】个快手程序的开始播放成功了\".format(i))\n",
    "        return True\n",
    "            \n",
    "# 开始OBS \n",
    "def begin_obs_play():\n",
    "    bResult = False\n",
    "        \n",
    "    obs_restore()\n",
    "    b_full_screen = is_obs_full_scree()\n",
    "    if b_full_screen == True:\n",
    "        print(\"OBS应用程序全屏显示\")\n",
    "        # 让应用程序置顶\n",
    "        set_app_forward()\n",
    "        if True == is_obs_playing():\n",
    "            print(\"当前正在播放\")\n",
    "            bResult = True\n",
    "        else:\n",
    "            print(\"当前没在播放\")\n",
    "            obs_start_or_pause()\n",
    "            time.sleep(2)\n",
    "            bResult = True\n",
    "    else:\n",
    "        print(\"!!!!!OBS应用程序没有全屏显示\")\n",
    "        bResult = False\n",
    "    \n",
    "    obs_smallest()\n",
    "    return bResult\n",
    "\n",
    "# 开始直播 \n",
    "# 说明：如果要直播成功，要求满足的条件参考上面的“使用者一定要准备的工作”：\n",
    "def begin_broadcat():\n",
    "    # 开始obs\n",
    "    bResult = begin_obs_play()\n",
    "    if bResult == False:\n",
    "        return False\n",
    "    # 开始快手直播伴侣的直播\n",
    "    bResult = begin_kuai_shou_play()\n",
    "    if bResult == False:\n",
    "        return False\n",
    "    \n",
    "    return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 停止快手直播(仅操作这一部分)\n",
    "def stop_kuai_shou_play__():\n",
    "    bResult = False\n",
    "    \n",
    "    b_full_screen = is_kuai_shou_full_scree()\n",
    "    if b_full_screen == True:\n",
    "        print(\"快手直播应用程序全屏显示\")\n",
    "        # 让应用程序置顶\n",
    "        set_app_forward()\n",
    "        time.sleep(0.5)\n",
    "        status = get_kuai_shou_status()\n",
    "        if KUAI_SHOUO_STUTUS.PLAYING == status:\n",
    "            print(\"当前正在直播\")\n",
    "            kuai_shou_start_or_stop()\n",
    "            time.sleep(2)\n",
    "            kuai_confirm_of_stop()\n",
    "            time.sleep(2)\n",
    "            kuai_know_of_stop()\n",
    "            time.sleep(2)\n",
    "            bResult = True\n",
    "        elif KUAI_SHOUO_STUTUS.STOPPED == status:\n",
    "            print(\"当前没在直播\")\n",
    "            bResult = True\n",
    "        elif KUAI_SHOUO_STUTUS.CONNECTING == status:\n",
    "            print(\"当前快手正在连接中\")\n",
    "            bResult = False\n",
    "        elif KUAI_SHOUO_STUTUS.OTHER == status:\n",
    "            print(\"当前快手应用程序被挡住\")\n",
    "            bResult = False\n",
    "    else:\n",
    "        print(\"!!!!!快手直播应用程序没有全屏显示\")\n",
    "        return False\n",
    "    kuai_smallest()\n",
    "    return bResult\n",
    "\n",
    "# 停止快手直播\n",
    "def stop_kuai_shou_play():\n",
    "    if 1 == COUNT_OF_KUAI_SHOU:\n",
    "        kuai_restore()\n",
    "        return stop_kuai_shou_play__()\n",
    "    else:\n",
    "        for i in range(COUNT_OF_KUAI_SHOU):\n",
    "            kuai_restore()\n",
    "            restore_selected_kuai_shou_app(i)\n",
    "            bResult = stop_kuai_shou_play__()\n",
    "            if bResult == False:\n",
    "                print(\"!!!!!第【{}】个快手程序的停止播放失败了\".format(i))\n",
    "                return False\n",
    "            else:\n",
    "                print(\"!!!!!第【{}】个快手程序的停止播放成功了\".format(i))\n",
    "        return True\n",
    "    \n",
    "# 停止OBS \n",
    "def stop_obs_play():\n",
    "    bResult = False\n",
    "        \n",
    "    obs_restore()\n",
    "    b_full_screen = is_obs_full_scree()\n",
    "    if b_full_screen == True:\n",
    "        print(\"OBS应用程序全屏显示\")\n",
    "        # 让应用程序置顶\n",
    "        set_app_forward()\n",
    "        if True == is_obs_playing():\n",
    "            print(\"当前正在播放\")\n",
    "            obs_stop()\n",
    "            time.sleep(2)\n",
    "            bResult = True\n",
    "        else:\n",
    "            print(\"当前没在播放\")\n",
    "            bResult = True\n",
    "    else:\n",
    "        print(\"!!!!!OBS应用程序没有全屏显示\")\n",
    "        bResult = False\n",
    "    \n",
    "    obs_smallest()\n",
    "    return bResult\n",
    "\n",
    "# 停止直播 \n",
    "# 说明：如果要停止直播成功，要求满足的条件参考上面的“使用者一定要准备的工作”：\n",
    "def stop_broadcat():\n",
    "    # 停止obs\n",
    "    bResult = stop_obs_play()\n",
    "    if bResult == False:\n",
    "        return False\n",
    "    # 停止快手直播伴侣的直播\n",
    "    bResult = stop_kuai_shou_play()\n",
    "    if bResult == False:\n",
    "        return False\n",
    "    \n",
    "    return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "当前的日期是:2022-12-01\n",
      "当前的时间是:19-16-47\n"
     ]
    }
   ],
   "source": [
    "date_str = datetime.datetime.now().strftime('%Y-%m-%d')\n",
    "time_str = datetime.datetime.now().strftime('%H-%M-%S')\n",
    "\n",
    "print(\"当前的日期是:{}\".format(date_str))\n",
    "print(\"当前的时间是:{}\".format(time_str))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'\\nbResult = begin_broadcat()\\nif bResult == False:\\n    print(\"!!!!开始直播失败\")\\nelse:\\n    print(\"^-^开始直播成功\")\\n\\n\\n\\nbResult = stop_broadcat()\\nif bResult == False:\\n    print(\"!!!!停止直播失败\")\\nelse:\\n    print(\"^-^停止直播成功\")\\n'"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    " \n",
    "\"\"\"\n",
    "bResult = begin_broadcat()\n",
    "if bResult == False:\n",
    "    print(\"!!!!开始直播失败\")\n",
    "else:\n",
    "    print(\"^-^开始直播成功\")\n",
    "\n",
    "\n",
    "\n",
    "bResult = stop_broadcat()\n",
    "if bResult == False:\n",
    "    print(\"!!!!停止直播失败\")\n",
    "else:\n",
    "    print(\"^-^停止直播成功\")\n",
    "\"\"\"  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "******配置开始直播的任务**********\n",
      "     【0】19:18\n",
      "     【1】13:30\n",
      "******配置停止直播的任务**********\n",
      "     【0】19:20\n",
      "     【1】14:30\n",
      "*******在【2022-12-01 19-17-08】开始了任务调度*******\n",
      "======================在【2022-12-01 19-18-00】执行了开始直直播任务====================\n",
      "点击【OBS界面还原】按钮\n",
      "OBS窗口【OBS 28.1.1 (64-bit, windows) - 配置文件: 未命名 - 场景: 未命名】的坐标是:(-8, -8, 1374, 736)\n",
      "Top banner保存到:./screenshot_img/top_banner.png\n",
      "OCR的结果： {'log_id': 1598275228227863463, 'words_result': [{'location': {'height': 12, 'top': 4, 'width': 348, 'left': 23}, 'words': 'OBS28.1.1(64-bit,windows)-配置文件：未命名-场晨：未命名'}, {'location': {'height': 14, 'top': 27, 'width': 41, 'left': 8}, 'words': '文件(F)'}, {'location': {'height': 15, 'top': 26, 'width': 42, 'left': 63}, 'words': '编辑(E)'}, {'location': {'height': 12, 'top': 28, 'width': 57, 'left': 106}, 'words': '视图V)'}, {'location': {'height': 14, 'top': 27, 'width': 69, 'left': 179}, 'words': '停靠窗口(D)'}, {'location': {'height': 12, 'top': 28, 'width': 67, 'left': 264}, 'words': '配置文件(P)'}, {'location': {'height': 15, 'top': 26, 'width': 26, 'left': 348}, 'words': '场景'}], 'words_result_num': 7}\n",
      "OBS应用程序全屏显示\n",
      "time_of_obs保存到:./screenshot_img/time_of_obs.png\n",
      "OCR的结果： {'log_id': 1598275238027744975, 'words_result': [{'location': {'height': 14, 'top': 3, 'width': 77, 'left': 3}, 'words': '-1'}], 'words_result_num': 1}\n",
      "当前没在播放\n",
      "点击【OBS界面点击开始或暂停】按钮\n",
      "点击【OBS界面最小化】按钮\n",
      "点击【快手界面还原】按钮\n",
      "快手直播伴侣窗口【快手直播伴侣】的坐标是:(0, 0, 1418, 813)\n",
      "Top banner保存到:./screenshot_img/top_banner.png\n",
      "OCR的结果： {'log_id': 1598275268494757165, 'words_result': [{'location': {'height': 20, 'top': 19, 'width': 135, 'left': 31}, 'words': '快手直播伴侣'}], 'words_result_num': 1}\n",
      "快手直播伴侣\n",
      "快手直播应用程序全屏显示\n",
      "status_of_kuai_shou保存到:./screenshot_img/status_of_kuai_shou.png\n",
      "OCR的结果： {'log_id': 1598275280259679652, 'words_result': [{'location': {'height': 16, 'top': 10, 'width': 68, 'left': 20}, 'words': '开始直播'}], 'words_result_num': 1}\n",
      "当前没在直播\n",
      "点击【快手界面点击开始或暂停】按钮\n",
      "点击【快手界面点击开播确定】按钮\n",
      "点击【快手界面最小化】按钮\n",
      "^-^开始直播成功\n"
     ]
    }
   ],
   "source": [
    "#\"\"\"\n",
    "####################### 任务调度 ############################\n",
    "def job_begin_broadcat(text=\"\"):\n",
    "    datetime_str = datetime.datetime.now().strftime('%Y-%m-%d %H-%M-%S')\n",
    "    print(\"======================在【{}】执行了开始直直播任务====================\".format(datetime_str))\n",
    "    bResult = begin_broadcat()\n",
    "    if bResult == False:\n",
    "        print(\"!!!!开始直播失败\")\n",
    "    else:\n",
    "        print(\"^-^开始直播成功\")\n",
    "\n",
    "def job_stop_broadcat(text=\"\"):\n",
    "    datetime_str = datetime.datetime.now().strftime('%Y-%m-%d %H-%M-%S')\n",
    "    print(\"======================在【{}】执行了开始停止直播任务====================\".format(datetime_str))\n",
    "    bResult = stop_broadcat()\n",
    "    if bResult == False:\n",
    "        print(\"!!!!停止直播失败\")\n",
    "    else:\n",
    "        print(\"^-^停止直播成功\")\n",
    "        \n",
    "# 每天执行开始直播的任务\n",
    "print(\"******配置开始直播的任务**********\")\n",
    "for i, begin_play_time in enumerate(g_BEGIN_PLAY_TIME_LIST):\n",
    "    print(\"     【{}】{}\".format(i, begin_play_time))\n",
    "    schedule.every().day.at(begin_play_time).do(job_begin_broadcat)\n",
    "    \n",
    "    \n",
    "# 每天执行停止直播的任务\n",
    "print(\"******配置停止直播的任务**********\")\n",
    "for i, stop_play_time in enumerate(g_STOP_PLAY_TIME_LIST):\n",
    "    print(\"     【{}】{}\".format(i, stop_play_time))\n",
    "    schedule.every().day.at(stop_play_time).do(job_stop_broadcat)\n",
    "\n",
    "datetime_str = datetime.datetime.now().strftime('%Y-%m-%d %H-%M-%S')\n",
    "print(\"*******在【{}】开始了任务调度*******\".format(datetime_str))\n",
    "while True:\n",
    "    # run_pending：运行所有可以运行的任务\n",
    "    schedule.run_pending()\n",
    "    time.sleep(1)\n",
    "#\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
